﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using TwitterClient2.Controller;
using NTwitter;

namespace TwitterClient2.Components
{
    class PanelMessage : Panel
    {
        private Label labelMessage;
        private LinkLabel linkLabelUsername;
        private string userName;
        private Message message;
        private TwitterClientController controller = TwitterClientController.getInstance();

        public PanelMessage(Message message)
        {
            this.userName = message.Sender.ScreenName;
            this.message = message;
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.labelMessage = new System.Windows.Forms.Label();
            this.linkLabelUsername = new System.Windows.Forms.LinkLabel();
            this.SuspendLayout();
            // 
            // labelMessage
            // 
            this.labelMessage.Location = new System.Drawing.Point(75, 0);
            this.labelMessage.Name = "labelMessage";
            this.labelMessage.Size = new System.Drawing.Size(125, 20);
            this.labelMessage.Text = this.message.Text;
            // 
            // linkLabelUsername
            // 
            this.linkLabelUsername.Location = new System.Drawing.Point(0, 0);
            this.linkLabelUsername.Name = "linkLabelUsername";
            this.linkLabelUsername.Size = new System.Drawing.Size(75, 20);
            this.linkLabelUsername.TabIndex = 0;
            this.linkLabelUsername.TabStop = false;

            this.linkLabelUsername.Text = this.userName;
            // 
            // PanelMessage
            // 
            this.Size = new System.Drawing.Size(200, 20);
            this.Click += new System.EventHandler(this.messageClick);
            this.Controls.Add(this.labelMessage);
            this.Controls.Add(this.linkLabelUsername);
            this.ResumeLayout(false);

        }

        private void messageClick(object sender, EventArgs eventArgs)
        {
            TwitterClientEvent tEvent = new TwitterClientEvent();
            tEvent.paramList.Add(this.message);
            this.controller.performUserInput(TwitterClientController.GET_MESSAGE_DETAILS, tEvent);
        }

        private void userNameClick(object sender, EventArgs args)
        {
            Cursor.Current = Cursors.WaitCursor;
            this.Parent.Enabled = false;
            LinkLabel linkLabel = (LinkLabel)sender;
            String user = linkLabel.Text;
            TwitterClientEvent tEvent = new TwitterClientEvent();
            tEvent.paramList.Add(user);
            tEvent.paramList.Add(PanelNavigation.MESSAGES_USERS);
            this.controller.performUserInput(TwitterClientController.USER_CLICK_HOME_OR_SEARCH, tEvent);
            this.Parent.Enabled = true;
            Cursor.Current = Cursors.Default;
        }
    }
}
